package com.gomyb.redis.message;

import com.gomyb.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.DependsOn;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/6/13 20:08
 */
@Slf4j
@DependsOn("redisService")
public abstract class MessageConsumerAbstract implements MessageConsumer {

    public String[] channels;

    public RedisService redisService;

    protected MessageConsumerAbstract() {
    }

    public void invoke() {
        redisService.subscribe((message, pattern) -> {
            try {
                handleMessage(new String(message.getBody()));
            } catch (Exception e) {
                e.printStackTrace();
                log.error("消息处理异常", e);
            }
        }, channels);
    }

}
